#include <iostream>
#include <vector>

using namespace std;

// 3439. 重新安排会议得到最多空余时间 I
// https://leetcode.cn/problems/reschedule-meetings-for-maximum-free-time-i/description/

class Solution
{
public:
    int maxFreeTime(int eventTime, int k, vector<int> &startTime, vector<int> &endTime)
    {
        int ans = 0;
        int n = startTime.size();
        int curSumFreeTime = 0;
        int left = 0;
        for (int i = 0; i <= n; i++)
        {
            int curFreeTime = 0;
            if (i == 0)
            {
                curFreeTime = startTime[i] - 0;
            }
            else if (i == n)
            {
                curFreeTime = eventTime - endTime[n - 1];
            }
            else
            {
                curFreeTime = startTime[i] - endTime[i - 1];
            }

            curSumFreeTime += curFreeTime;

            if(i - left + 1 < k + 1){
                continue;
            }

            ans = max(ans, curSumFreeTime);

            int preFreeTime = 0;
            if (left == 0)
            {
                preFreeTime = startTime[left] - 0;
            }
            else if (left == n)
            {
                preFreeTime = eventTime - endTime[n - 1];
            }
            else
            {
                preFreeTime = startTime[left] - endTime[left - 1];
            }

            curSumFreeTime -= preFreeTime;
            left++;
        }
        return ans;
    }
};

int main()
{
    return 0;
}